package GameLogic;

public class EntityPlayer extends Entity {
	
		public float collisionRadius;
		public float velocitymodifier;
		private float velFactor;
		public int score;
		private boolean playingAnim;
		private boolean flip;
		private int currentFrame;
		private double grace;
		
		public EntityPlayer()
		{
			model = new EntityModel();
			model.texture_path = "res/Toki2";
			eCoord.animFrame = 0;
			model.frames=6;                            //model does not have any frames
	        model.texture_coordinates=new float[] {0.0f, 0.0f,      //quad vertices; NOTICE: if you start with 0 as bottom left vertex
	                                     0.0f, 1.0f,       // it will spin around this vertex (rotate is performed on 0,0)
	                                     1.0f, 1.0f,
	                                     1.0f, 0.0f};
	        model.vertex_colour = new float[] {0.0f, 0.0f, 0.0f, 1.0f,  //RGBA, each vertex of quad
	                                        0.0f, 0.0f, 0.0f, 1.0f,
	                                        0.0f, 0.0f, 0.0f, 1.0f,
	                                        0.0f, 0.0f, 0.0f, 1.0f};
	         model.vertices = new float[] {-0.125f, -0.125f,      //quad vertices; NOTICE: if you start with 0 as bottom left vertex
	                                     0.125f, -0.125f,       // it will spin around this vertex (rotate is performed on 0,0)
	                                     0.125f, 0.125f,
	                                     -0.125f, 0.125f};
			collisionRadius = 0.5f;
			health = 100;
			score = 0;
			currentFrame = 0;
			velFactor = 1.5f;
			grace = 0;
			flip = false;
		}
	
		public void tick()
		{
			if(playingAnim)
			{
				if(eCoord.animFrame < model.frames)
				{
					if(currentFrame < model.frames-1)
					{
						eCoord.animFrame += 1;
					}
					else if(currentFrame >= model.frames+2 && eCoord.animFrame > 0)
					{
						eCoord.animFrame -= 1;
					}
				}
			currentFrame++;
				if(currentFrame >= 15)
				{
					playingAnim = false;
					currentFrame = 0;
				}
			}
			
			if(grace >= 0)
			{
				grace -= 0.0041f;
			}
		}
		
		public void attack()
		{
			playingAnim = true;
		}
		
		public void activateGrace()
		{
			grace = 1.5f;
		}
		
		public boolean isGrace()
		{
			return grace > 0;
		}
		
		public void updateMovementByPath()
		{
			
		}
		
		public void move(double xspeed, double yspeed)
		{
			moveHoriz(xspeed, 0);
			moveVer(0, yspeed);
		}
		
		private void moveHoriz(double xspeed, double yspeed)
		{
			eCoord.posX += velFactor*xspeed;
			eCoord.posX += velFactor*yspeed;
		}		
		
		private void moveVer(double xspeed, double yspeed)
		{
			eCoord.posY += velFactor*xspeed;
			eCoord.posY += velFactor*yspeed;
		}
		
		public void damage(int dval)
		{
			health -= dval;
		}
		
		public void awardScore(int scoreAward)
		{
			score += scoreAward;
		}
}
